package com.mmall.controller.backend;


import com.mmall.common.ServerResponse;
import com.mmall.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created by
 */
@Controller
@RequestMapping("/manage/category")
public class CategoryManageController {

    @Autowired
    private ICategoryService iCategoryService;

    @RequestMapping("add_category")
    @ResponseBody
    public ServerResponse addCategory(String categoryName, @RequestParam(value = "parentId",defaultValue = "0") int parentId){
        //登录验证交给过滤器
        //增加我们处理分类的逻辑
        return iCategoryService.addCategory(categoryName,parentId);
    }

    @RequestMapping("set_category_name")
    @ResponseBody
    public ServerResponse setCategoryName(Integer categoryId, String categoryName){
        //登录验证交给过滤器
        return iCategoryService.updateCategoryName(categoryId,categoryName);
    }

    @RequestMapping("get_category")
    @ResponseBody
    public ServerResponse getChildrenParallelCategory(@RequestParam(value = "categoryId" ,defaultValue = "0") Integer categoryId){
        //登录验证交给过滤器
        //查询子节点的category信息,并且不递归,保持平级
        return iCategoryService.getChildrenParallelCategory(categoryId);

    }

    @RequestMapping("get_deep_category")
    @ResponseBody
    public ServerResponse getCategoryAndDeepChildrenCategory(@RequestParam(value = "categoryId" ,defaultValue = "0") Integer categoryId){


        //登录验证交给过滤器
        //查询当前节点的id和递归子节点的id
//            0->10000->100000
        return iCategoryService.selectCategoryAndChildrenById(categoryId);
    }

}
